#include "stdafx.h"
#include "DataBaseManager.h"


DataBaseManager::DataBaseManager(void)
{
	Movie movie_;
	movie_.setName("Basha");
	_movies.push_back(movie_);

	Member member_;
	member_.getDetails().setUserName("Hazem");
	_members.push_back(member_);
}

DataBaseManager::~DataBaseManager(void)
{
}

void DataBaseManager::connect()
{
	//driver = get_mysql_driver_instance();
	//conn = driver->connect("localhost", "root", "password");
	//stmt = conn->createStatement();
}

void DataBaseManager::close()
{
	//delete stmt;
	//delete conn;
}

bool DataBaseManager::checkPassword(string password_)
{
	
	return false;
}

void DataBaseManager::editPassword(string newPassword_)
{
	//stmt->execute("INSERT INTO Rental(password) VALUES (newPassword_)");
}

void DataBaseManager::reserveFilm(int movieID_, int id_)
{
}

void DataBaseManager::cancelResevedMovie(int movieID_)
{
}

vector<Member> DataBaseManager::getReservers(int moviesID_)
{
	return _members;
}

vector<Member> DataBaseManager::getRenters(int dvdsID_)
{
	return _members;
}

//vector<Movie> DataBaseManager::getMyReservations(int memberID_)
//{
//	return 0;
//}
//
//vector<DVD> DataBaseManager::getMyRentals(int memberID_)
//{
//	return 0;
//}

void DataBaseManager::addAccount(MemberDetails details_)
{
}

MemberDetails DataBaseManager::searchMemberDetails(string userName_)
{
	MemberDetails details;
	return details;
}

void DataBaseManager::addDVD(int movieID_, string barcode_)
{
}

void DataBaseManager::removeDVD(int movieID_, string barcode_)
{
	for (int i = 0; i < _movies[movieID_].getPieces().size(); i++)
		if (_movies[movieID_].getPieces()[i].getBarCode() == barcode_)
			_movies[movieID_].getPieces().erase(_movies[movieID_].getPieces().begin() + i);
}

void DataBaseManager::addFilm(Movie movie_)
{
	_movies.push_back(movie_);
}

//void DataBaseManager::rentFilm(Rental operation_)
//{
//}
//
//void DataBaseManager::endRentFilm(Rental operation_)
//{
//}


vector<Movie> DataBaseManager::searchFilm(string movieName_)
{
	vector<Movie> movies_;
	for (int i = 0; i < _movies.size(); i++)
	{
		if(_movies[i].getName() == movieName_)
			movies_.push_back(_movies[i]);
	}
	return movies_;
}

vector<Movie> DataBaseManager::filter(string type_)
{
	vector<Movie> movies_;
	return movies_;
}

vector<Member> DataBaseManager::getAllMembers()
{
	return _members;
}

Member DataBaseManager::getMember(string userName_)
{
	int i;
	for (i = 0; i < _members.size(); i++)
	{
		if(_members[i].getDetails().getUserName() == userName_)
			break;
	}
	return _members[i];
}

Member DataBaseManager::getMember(int memberID_)
{
	return _members[memberID_];
}

vector<Movie> DataBaseManager::getAllMovies()
{
	return _movies;
}

Movie DataBaseManager::getMovie(int movieID_)
{
	int i;
	for (i = 0; i < _members.size(); i++)
	{
		if(_movies[i].getID() == movieID_)
			break;
	}
	return _movies[i];
}